'''
@Project ：hdcms-scripts
@File    ：api_live_room.py
@IDE     ：PyCharm
@Author  ：朱广杰
@Date    ：2024/11/11 18:36
'''
import time


from script.api.base_api import BaseCallbackApi, BaseCapiApi, BaseCmsv2Api
from common.time_util import get_now_timestamp
from common.FILE_PATH import load_yaml_file, BASE_DIR, read_excel


#  用户加入直播间聊天室
class JoinLiveApi(BaseCallbackApi):
    def __init__(self, user_id: str,chat_room_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/tencent/im/common/callback'
        self.method = 'post'
        self.json = {
            "SdkAppId": "1400118932",
            "CallbackCommand": "Group.CallbackAfterNewMemberJoin",
            "ContentType": "json",
            "ClientIP": "221.217.88.94",
            "OptPlatform": "iOS",
            "GroupId": str(chat_room_id),
            "Type": "AVChatRoom",
            "From_Account": "",
            "MsgSeq": 0,
            "MsgTime": 0,
            "MsgBody": None,
            "Info": {
                "Action": "",
                "To_Account": "",
                "Reason": ""
            },
            "EventType": "",
            "MemberList": None,
            "NewMemberList": [
                {
                    "Member_Account": user_id
                }
            ],
            "ExitMemberList": None
        }

# 获取课程的直播间信息
class GetLiveInfoApi(BaseCmsv2Api):
    def __init__(self, course_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/live_config_info'
        self.method = 'get'
        self.params = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "course_id": course_id
        }


#  修改直播间主持人
class UpdateLiveInfoApi(BaseCmsv2Api):
    def __init__(self, course_id: str, zuser_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/edit_live_config_info'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "live_state": 2,
            "prevue_path": "",
            "is_display_ask": 0,
            "free_trial_duration": 300,
            "free_trial_content": "",
            "live_exit_toast": 1,
            "ask_question_switch": 1,
            "course_live_type": 2,
            "preside_live_obj": {

            },
            "is_open_stake": 0,
            "live_start_time": "",
            "dm_sync_time": "",
            "is_flowhouse_demo": 1,
            "allow_preside_close": 1,
            "course_id": course_id,
            "preside_user_id": zuser_id,
            "versionName": self.common['versionName']
        }

class UpdateFlowHouseInfoApi(BaseCmsv2Api):
    def __init__(self, course_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/edit_flowhouse_info'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "course_id": course_id,
            "conference_obj": {
                "conference_mode_is": 0,
                "conference_url": ""
            },
            "flowhouse_obj": {
                "flowhouse_form_id": 0,
                "flowhouse_wish_type": 3,
                "flowhouse_tip_is": 1,
                "wish_user_cnt": 0,
                "flowhouse_tag_allocate_mode_is": 0,
                "flowhouse_mode_is": 1,
                "flowhouse_desc_list": [
                    "022年11月，ChatGPT的推出不仅标志着智能革命新纪元的到来，更显露了人工智能（AI）从科幻走向现实，成为重塑我们生活和工作方式的强劲力量。2023年GPT-4的亮相，以及GPT系列产品的持续革新，让我们亲眼目睹了AI速度和能力的惊人飞跃。现在，通用人工智能（AGI）的曙光已在地平线上闪现，虽未完全成形，却似乎触手可及。这不仅预示着技术的飞跃，更预兆着对人类社会结构和认知方式的根本革新。科学家们对通用人工智能（AGI）的到来提出了各种预测，其中一些观点预测这一转折点可能在2029年到来。另外，所谓的“技术奇点”——那个机器智能超越全部人类智能的时刻，有预测认为可能在2045年左右出现。这两个预期时刻分别代表着AI能力的重要发展阶段，以及一个更加深远的未来场景。在这个未来场景中，AI的进步可能带来根本性的、不可逆转的巨大变革。深度学习之父Geoffrey Hinton将脑科学的原理应用于开发类人脑工作方式的算法，收获巨大成功。他对人工神经网络的深刻洞见与坚持，源自于他的心理学背景和对人类大脑的深度理解。同样地，本堂课中，刘嘉教授作为一位在心理学、脑科学与人工智能交汇处深"
                ]
            }
        }


#  主持人开启讨论
class DiscussOpenApi(BaseCapiApi):
    def __init__(self, zuser_id: str,course_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/discuss/open'
        self.method = 'post'
        self.json = {
            "discuss_duration": 0,
            "flowhouse_steps": [
                {
                    "duration": 2,
                    "duration_limit": 5,
                    "duration_min": 0,
                    "duration_type": 2,
                    "introduce": "探索前的身心放松，聚焦当下。",
                    "step_id": 0,
                    "step_type": 0,
                    "title": "临在"
                },
                {
                    "duration": 4,
                    "duration_limit": 100,
                    "duration_min": 0,
                    "duration_type": 1,
                    "introduce": "",
                    "step_id": 0,
                    "step_type": 1,
                    "title": "表达"
                },
                {
                    "duration": 20,
                    "duration_limit": 120,
                    "duration_min": 1,
                    "duration_type": 2,
                    "introduce": "",
                    "step_id": 0,
                    "step_type": 2,
                    "title": "呼应"
                },
                {
                    "duration": 15,
                    "duration_limit": 120,
                    "duration_min": 1,
                    "duration_type": 2,
                    "introduce": "",
                    "step_id": 0,
                    "step_type": 3,
                    "title": "看见"
                }
            ],
            "group_user_num": 5,
            "last_discuss_is": 0,
            "notice_add_is": 0,
            "notice_content": "",
            "obj_id": course_id,
            "obj_type": 1,
            "clientType": "23116PN5BC_android_14",
            "company_id": "0",
            "user_id": zuser_id,
            "imei": "93a8fee28063cab8c46557e588dc2b7c",
            "device_type": "phone",
            "client_type": "android",
            "versionName": self.common['versionName'],
            "appChannel": "xiaomi",
            "ts": get_now_timestamp()
        }


#  用户同意加入讨论间
class WishJoinRoomApi(BaseCapiApi):
    BaseCapiApi.capi_token = '1'
    def __init__(self, user_id: str,course_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/discuss/set_discuss_wish'
        self.method = 'post'
        self.json = {
          "course_id": course_id,
          "user_id": user_id,
          "is_wish": 1,
          "versionName": self.common['versionName']
        }

#  同意后进入预分配讨论间
class GetRoomInfoApi(BaseCapiApi):
    BaseCapiApi.capi_token = '1'
    def __init__(self, user_id: str,discuss_room_id: str, discuss_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/discuss_room/get_room_info'
        self.method = 'get'
        self.params = {
          "room_id": discuss_room_id,
          "user_id": user_id,
          "discuss_id": discuss_id,
          "versionName": self.common['versionName']
        }

#  用户进入讨论间
class JoinLiveRoomApi(BaseCallbackApi):
    def __init__(self, user_id: str,room_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/tencent/trtc/common/callback'
        self.method = 'post'
        self.json = {
            "EventGroupId":	1,
            "EventType":	103,
            "CallbackTs":	1719318954965,
            "EventInfo":	{
                "RoomId":	room_id,
                "UserId":	user_id,
                "EventTs":	1719318954,
                "EventMsTs":	1719318954958,
                "Role":	20,
                "Reason":	1
            }
        }

#  主持人关闭讨论
class DiscussCloseApi(BaseCapiApi):
    def __init__(self, zuser_id: str,course_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/discuss/close'
        self.method = 'post'
        self.json = {
            "obj_id": course_id,
            "obj_type": 1,
            "user_id": zuser_id,
            "versionName": self.common['versionName']
        }

if __name__ == '__main__':
    # JoinLiveApi(chat_room_id='133437', user_id='1e0caa4dc33ecc90908dbf4ddc210128').send()
    # UpdateLiveInfoApi(course_id='b2dfa8ff218d3e1258395274049e188e', zuser_id='374a2b4762b7938337af9ddec0a3218a').send()
    # UpdateFlowHouseInfoApi(course_id='b2dfa8ff218d3e1258395274049e188e').send()
    # DiscussOpenApi(course_id='b2dfa8ff218d3e1258395274049e188e', zuser_id='374a2b4762b7938337af9ddec0a3218a').send()
    # WishJoinRoomApi(course_id='b2dfa8ff218d3e1258395274049e188e', user_id='1e0caa4dc33ecc90908dbf4ddc210128').send()
    aa = GetLiveInfoApi(course_id='b2dfa8ff218d3e1258395274049e188e').send()
    print(aa.json())




